<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
use common\models\Goods;
use yii\helpers\ArrayHelper;
use kartik\datecontrol\DateControl;
use common\models\GoodsManager;
use common\models\GoodsCategory;

/* @var $this yii\web\View */
/* @var $model common\models\GoodsManager */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="box box-primary">
    <div class="box-body">
    <?php $form = ActiveForm::begin(); ?>
    <?= $form->field($model, 'category_id')->widget(Select2::className(),[
        'options' => ['placeholder' => '请选择分类'],
        'data'=>ArrayHelper::map(GoodsCategory::find()->all(),'id','category_name'),
        'pluginEvents' =>[
            "select2:select" => "function() {
              var id=$(this).val();
              $.get('/goods-manager/get-goods?id='+id,function(res){
              console.log(22);
              $('#goods_id').html(res);
              });
         }",
        ]
    ])->label('物品分类')?> 
    <?= $form->field($model, 'goods_id')->widget(Select2::className(),[
        'options' => ['placeholder' => '请选择物品','id'=>'goods_id'],
        'data'=>ArrayHelper::map(Goods::find()->all(),'id','name')
    ])->label('物品')?>
    <?= $form->field($model, 'borrower')->textInput(['maxlength' => true]) ?>
    <?= $form->field($model, 'created_at')->widget(DateControl::className(), [
    'type'=>DateControl::FORMAT_DATE,
    'ajaxConversion'=>false,
    'autoWidget'=>true,
    'widgetOptions' => [
        'options' => ['placeholder' => 'Select operating time ...'],
        'pluginOptions' => [
            'autoclose' => true,
            'todayHighlight' => true
        ]
    ]])?>
    <?= $form->field($model, 'return_time')->widget(DateControl::className(), [
//     'type'=>DateControl::FORMAT_DATE,
    'ajaxConversion'=>false,
    'autoWidget'=>true,
//     'type'=>DateControl::FORMAT_TIME,
        
    'widgetOptions' => [
        'options' => ['placeholder' => 'Select operating time ...'],
        'pluginOptions' => [
            'autoclose' => true,
            'todayHighlight' => true
        ]
    ]])?>
   <?php
   if(!$model->isNewRecord)
   {
       echo $form->field($model, 'status')->widget(Select2::className(),[
           'options' => ['placeholder' => '请选择状态'],
           'data'=>GoodsManager::STATUS
    ])->label('状态'); 
   }
  ?>
    <?php
   if(!$model->isNewRecord)
   {
      echo  $form->field($model, 'real_return_time')->widget(DateControl::className(), [
    'type'=>DateControl::FORMAT_DATE,
    'ajaxConversion'=>false,
    'autoWidget'=>true,
    'widgetOptions' => [
        'options' => ['placeholder' => 'Select operating time ...'],
        'pluginOptions' => [
            'autoclose' => true,
            'todayHighlight' => true
        ]
    ]]);
}?>
    <?= $form->field($model, 'mark')->textarea(['maxlength' => true]) ?>
    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success btn-flat' : 'btn btn-primary btn-flat']) ?>
    </div>

    <?php ActiveForm::end(); ?>
    </div>
</div>
